package com.example.studentcompetitionplatform.service.impl;

import com.example.studentcompetitionplatform.entity.Competitions;
import com.example.studentcompetitionplatform.entity.Registrations;
import com.example.studentcompetitionplatform.mapper.JingSaiBaoMingMapper;
import com.example.studentcompetitionplatform.service.IJingSaiBaoMingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class JingSaiBaoMingService implements IJingSaiBaoMingService {
    @Resource
    private JingSaiBaoMingMapper jingSaiBaoMingMapper;

    @Override
    public void insertR(Registrations registrations) {
        if (jingSaiBaoMingMapper.findRegistrations(registrations)!=null){
            System.out.println("已经报过名了");
        }
        jingSaiBaoMingMapper.insertRegistrations(registrations);
    }

    @Override
    public Map<String, Object> page(Integer pageNum, Integer pageSize, Integer competitionId) {
        pageNum = (pageNum - 1) * pageSize;
        if (competitionId == 0) {
            competitionId = null;
        }
        List<Competitions> data = jingSaiBaoMingMapper.selectPage(pageNum, pageSize, competitionId);
        Integer total = jingSaiBaoMingMapper.findCompetitionTotal(competitionId);
        Map<String, Object> res = new HashMap<>();
        res.put("data", data);
        res.put("total", total);
        return res;
    }

}
